package com.robot.matchingsystem.controller.matchingHandle;

import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.robot.matchingsystem.service.matchingHand.matchingHandleService;

import java.util.Map;

@RestController
public class matchingHandleController {
    @Autowired
    matchingHandleService matchingHandleService;
    @PostMapping("/player/add/")
    String addPlayer(@RequestParam MultiValueMap<String,String> map, HttpServletRequest request){
        String ip = request.getRemoteAddr();
        if(!ip.equals("127.0.0.1")) return null;
        Integer uid = Integer.parseInt(map.getFirst("userid"));
        Integer score = Integer.parseInt(map.getFirst("score"));
        Integer botId = Integer.parseInt(map.getFirst("botid"));
        return matchingHandleService.addPlayer(uid,score,botId);
    }
    @PostMapping("/player/remove/")
    String removePlayer(@RequestParam MultiValueMap<String,String> map,HttpServletRequest request){
        String ip = request.getRemoteAddr();
        if(!ip.equals("127.0.0.1")) return null;
        Integer uid = Integer.parseInt(map.getFirst("userid"));
        return matchingHandleService.removePlayer(uid);
    }
}
